package cn.tedu.luban.order.main.service;

import cn.tedu.luban.order.main.repository.OrderRepository;
import cn.tedu.luban.order.protocol.bo.AttachInfoBO;
import cn.tedu.luban.order.protocol.bo.OrderBO;
import cn.tedu.luban.order.protocol.query.AdminOrderListQuery;
import com.tedu.inn.protocol.ListRecordTotalBO;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderAdminService {
    @Autowired
    private OrderRepository orderRepository;
    public ListRecordTotalBO<OrderBO> queryOrders(AdminOrderListQuery adminOrderListQuery) {
        Long totalRecord = this.orderRepository.countOrders(adminOrderListQuery);
        List<OrderBO> orderBoList = new ArrayList<>();
        if (totalRecord > 0) {
            orderBoList = this.orderRepository.queryOrders(adminOrderListQuery);
        }
        return new ListRecordTotalBO<>(orderBoList, totalRecord);
    }

    public OrderBO detailOrder(Long id) {
        List<AttachInfoBO> attachInfoBOS=new ArrayList<>();
        AttachInfoBO attachInfoBO=new AttachInfoBO();
        attachInfoBO.setUrl("http://localhost:8092/static"+"CE8FEE9B1C3B44B199942444CE322D88.png");
        attachInfoBOS.add(attachInfoBO);
        OrderBO orderBO = this.orderRepository.getOrderById(id);
        orderBO.setAttachInfoBO(attachInfoBOS);
        return orderBO;
    }
}
